package org.xlp.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Description: map操作工具类
 * <br/>date: 2024/11/27 23:21
 *
 * @version 1.0
 * @author: xlp
 */
public class MapUtils {
    /**
     * 创建MapBuilder对象
     * @return
     */
    public static <K, V> MapBuilder<K, V> builder(){
        return new MapBuilder<>();
    }

    public static class MapBuilder<K, V> {
        private Map<K, V> map;

        MapBuilder(){
            map = new HashMap<>();
        }

        public MapBuilder<K, V> put(K key, V value){
            map.put(key, value);
            return this;
        }

        public MapBuilder<K, V> putAll(Map<? extends K, ? extends V> m){
            map.putAll(m);
            return this;
        }

        public MapBuilder<K, V> remove(K key){
            map.remove(key);
            return this;
        }

        public V get(K key){
            return map.get(key);
        }

        public Map<K, V> map(){
            return map;
        }
    }
}
